package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation {
    @Override
    public void work(BookList booklist) {
        System.out.println("归还图书！");
        System.out.println("输入你要归还的图书");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentSize = booklist.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = booklist.getBook(i);
            //这里将输入的书名与书架中的书名进行比较并且查看是否被借出，因为isBorrowed属性在设置的时候为Boolean类型，所以用true来判断
            if(book.getName().equals(name)&&book.isBorrowed()==true){
                book.setBorrowed(false);
                System.out.println("归还成功");
                return;
            }
        }
    }
}
